import HttpRequest from '@/libs/axios'
import ax from 'axios'
import request from '@/libs/request'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro

export const axios = new HttpRequest(baseUrl)

export const getRequest = (url, params) => {
  return ax.request({
    method: 'get',
    url,
    params: params
  })
}

export const postRequest = (url, params) => {
  return ax.request({
    method: 'post',
    url,
    data: params
  })
}
export const postFormRequest = (url, params) => {
  return ax.request(url, {
    method: 'POST',
    body: params ? transacionParamsToUrl(params) : params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export const downloadRequest = (url, params) => {
  return ax.request({
    method: 'post',
    url,
    data: params,
    responseType: 'blob'
  })
}

export const uploadFileRequest = (url, params) => {
  return ax.request({
    method: 'post',
    url,
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
